package com.stt.experiment.trynetty.server;

import com.stt.experiment.trynetty.buffer.RequestBuffer;
import com.stt.experiment.websocket.action.dispatcher.ActionDispatcher;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RequestManager {

    private final ActionDispatcher actionDispatcher;

    @Autowired(required = false)
    public RequestManager(ActionDispatcher actionDispatcher) {
        this.actionDispatcher = actionDispatcher;
    }

    /**
     * 处理请求的转发
     * @param buffer 请求
     */
    public void doRequest(RequestBuffer buffer) {
        try {
            // 分发请求
            actionDispatcher.doDispatcher(buffer.getModule(), buffer.getCmd(), buffer).get();
        } catch (Exception e ) {
            e.printStackTrace();
        }
    }
}
